<template>
    <!-- 党务监督 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button
                class="mb12"
                icon="plus"
                type="primary"
                @click="handleManage(2)"
                v-btnPermission="'di_0011_add_01'"
                >新增</a-button
            >
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <template slot="action" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'di_0011_loo_04'">查看</a>
                    <a
                        @click="handleManage(-1, record)"
                        v-if="record.downStatus == 0"
                        v-btnPermission="'di_0011_rwd_05'"
                        >任务下达</a
                    >
                    <a @click="handleManage(1, record)" v-if="record.upStatus != 3" v-btnPermission="'di_0011_edi_02'"
                        >编辑</a
                    >
                    <a
                        class="del_btn"
                        v-if="record.downStatus == 0"
                        @click="handleRemove(record.id)"
                        v-btnPermission="'di_0011_del_03'"
                        >删除</a
                    >
                    </MoreButton>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import {
    getPageSuperviseTaskDown,
    deleteSuperviseTaskDown,
    downTaskByDownId,
} from '@/api/disciplineInspection/supervision' // api
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import SelectTreeUnion from '@/components/Select/SelectTreeUnion' // 工会
const searchArr = [
    // 搜索框
    {
        name: '任务名称',
        type: 'input',
        value: 'taskName',
    },
    {
        name: '层级',
        type: Selector,
        valueKey: 'level',
        selectType: '1',
        urlType: 'union',
    },
    {
        name: '单位',
        type: 'input',
        value: 'orgStr',
    },
    {
        name: '下达状态',
        value: 'downStatus',
        type: 'select',
        data: [
            {
                label: '已下达',
                value: '1',
            },
            {
                label: '未下达',
                value: '0',
            },
        ],
    },
    {
        name: '上报情况',
        value: 'upStatus',
        type: 'select',
        data: [
            {
                label: '全部完成',
                value: '3',
            },
            {
                label: '部分完成',
                value: '2',
            },
            {
                label: '暂无数据',
                value: '1',
            },
        ],
    },
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        },
    },
    {
        title: '任务名称',
        ellipsis: true,
        dataIndex: 'taskName',
    },
    {
        title: '层级',
        ellipsis: true,
        dataIndex: 'levelStr',
    },
    {
        title: '单位',
        ellipsis: true,
        dataIndex: 'orgStr',
    },
    {
        title: '时间',
        ellipsis: true,
        dataIndex: 'taskDateStart',
        customRender(text, record, index) {
            return record.taskDateStart + ' - ' + record.taskDateEnd
        },
    },
    {
        title: '下达状态',
        ellipsis: true,
        dataIndex: 'downStatusStr',
    },

    {
        title: '上报情况',
        ellipsis: true,
        dataIndex: 'upStatusStr',
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        align: 'center',
        scopedSlots: { customRender: 'action' },
    },
]
import { typeListApproval } from '@/utils/util'
export default {
    name:'a'+ Date.now(),
    extends: new BasePage(),
    components: {
        STable,
        SelectTreeUnion,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
                return getPageSuperviseTaskDown(requestParameters).then((res) => {
                    return res
                })
            }, // 加载数据方法 必须为 Promise 对象
            removeApi: { remove: deleteSuperviseTaskDown }, // api
        }
    },
    methods: {
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            if (type == -1) {
                this.$confirm({
                    title: '温馨提示',
                    content: '请确定是否要下达任务？',
                    onOk: () => {
                        return downTaskByDownId(record.id).then(() => {
                            this.$message.success('下达成功！')
                            this.$refs.table.loadData()
                        })
                    },
                })

                return
            }
            let query = {
                editModel: type,
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: '/disciplineInspection/supervision/supervisionTaskDwon/updateSupervisionTaskDwon',
                query,
            })
        },
    },
}
</script>
